package ar.edu.itba.infovis.TPF.twitter;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.joda.time.DateTime;

import ar.edu.itba.infovis.TPF.json.CustomJSONTwitterDateDeserializer;

@JsonIgnoreProperties(ignoreUnknown=true)
public class Tweet implements Comparable<Tweet> {

	private DateTime created_at;
	private Long id; // Used for HashCode and equals
	private String in_reply_to_screen_name;
	private Integer retweet_count;
	private Boolean retweeted;
	private String text;
	private TwitterUser user;
	
	public DateTime getCreated_at() {
		return created_at;
	}
	
	@JsonDeserialize(using = CustomJSONTwitterDateDeserializer.class)
	public void setCreated_at(DateTime created_at) {
		this.created_at = created_at;
	}
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getIn_reply_to_screen_name() {
		return in_reply_to_screen_name;
	}
	
	public void setIn_reply_to_screen_name(String in_reply_to_screen_name) {
		this.in_reply_to_screen_name = in_reply_to_screen_name;
	}
	
	public Integer getRetweet_count() {
		return retweet_count;
	}
	
	public void setRetweet_count(Integer retweet_count) {
		this.retweet_count = retweet_count;
	}
	
	public Boolean getRetweeted() {
		return retweeted;
	}
	
	public void setRetweeted(Boolean retweeted) {
		this.retweeted = retweeted;
	}
	
	public String getText() {
		return text;
	}
	
	public void setText(String text) {
		this.text = text;
	}
	
	public TwitterUser getUser() {
		return user;
	}
	
	public void setUser(TwitterUser user) {
		this.user = user;
	}
	//Primero van los mas nuevos
	@Override
	public int compareTo(Tweet otherTweet) {
		//return this.getCreated_at().compareTo(otherTweet.getCreated_at());
		return otherTweet.getCreated_at().compareTo(this.getCreated_at());
	}
		
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tweet other = (Tweet) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Tweet [created_at=" + created_at + ", id=" + id + ", text="
				+ text + ", user=" + user + "]";
	}

}
